SpringBoot默认tomcat作为内置的Servlet容器.spring-boot-starter-web pom.xml文件description有如下描述.

Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container

pom文件中有spring-boot-starter-tomcat依赖,spring-boot-starter-tomcat中又包含了tomcat.但是修改为jetty也十分简单.

修改为 jetty 仅需两步.

Step1. 移除默认的Tomcat 依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Step2.添加 jetty 依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

spring-boot-starter-parent pom的parent是spring-boot-dependencies,其dependencyManagement中有jetty的依赖.

因此添加 jetty 依赖时无需再指定版本.修改后重新启动.

mvn spring-boot:run

留言